<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5shiv.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css" />
<!--[if IE 6]>
<script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>添加管理员 - 管理员管理 - 胆款流转实时监控管理系统 v1.0</title>
<meta name="keywords" content="胆款流转实时监控管理系统 v1.0">
<meta name="description" content="胆款流转实时监控管理系统 v1.0">
</head>
<body>

<article class="page-container">
	<form class="form form-horizontal" id="form-admin-add">
	<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>所属公司：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<select class="select" id="enterprise" name="enterprise">
					<option value="000">请选择分公司</option>
				</select>
			</div> 
	</div>
		
		
	<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>所属角色：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<select class="select" id="status" name="status">
					<option value="000">请选择角色</option>
				</select>
			</div>
		</div> 
	
	
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>所属部门：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<select class="select" id="status2" name="status2">
					<option value="000">请选择</option>
				</select>
			</div>
		</div>
		
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>账号：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value=""  maxlength="11"  onkeyup="this.value=this.value.replace(/\D/g,'')" id="account" name="account">
			</div>
		</div>
		
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>姓名：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="" maxlength="20"  onkeyup="value=value.replace(/[^\w\u4E00-\u9FA5]/g, '')" id="userName" name="userName">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>密码：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="password" class="input-text" id='password' type="password"  onkeyup="value=value.replace(/[^\w\u4E00-\u9FA5]/g, '')"   maxlength="18">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>确认密码：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="password" class="input-text" id='password_confirm' type="password"  onkeyup="value=value.replace(/[^\w\u4E00-\u9FA5]/g, '')"  maxlength="18">
			</div>
		</div>
		
		
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
				<!-- <input class="btn btn-primary radius" id="submitId" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;"> -->
				<input class="btn btn-primary radius" onclick="regClick()" id="reg"  type="button" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
			</div>
		</div>
	</form>
</article>




<!--_footer 作为公共模版分离出去--> 
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script> 
<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="lib/jquery.validation/1.14.0/jquery.validate.js"></script> 
<script type="text/javascript" src="lib/jquery.validation/1.14.0/validate-methods.js"></script> 
<script type="text/javascript" src="lib/jquery.validation/1.14.0/messages_zh.js"></script> 
<script type="text/javascript" src="js/jquery.base64.js"></script>
<script type="text/javascript">
//var muser_service = 'http://39.100.91.49:8092/';
$(function(){
	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});
	
	//queryCompanyOfficeProfession()
	
		optionStatus();//查询公司
		
		window.addEventListener('goReg',function(event){
			$("#account").val("");
			$("#password").val("");
			$("#password_confirm").val("");
		//	$("#userName").val("");
			$("#name").val("");
			$("#enterprise").val("");
		//	$("#address").val("");
			$("#status").val("");
		});
	
});

function 	regClick(){
	
	var regButton = document.getElementById('reg');//注册按钮
	var accountBox = document.getElementById('account');//账号
	var passwordBox = document.getElementById('password');//密码
	var passwordConfirmBox = document.getElementById('password_confirm');//确认密码
	//var userName = document.getElementById('userName');//员工编号
	var name = document.getElementById('userName');//名称
	var enterprise = document.getElementById('enterprise');//所属公司
	//var address = document.getElementById('address');//地质
	var status = document.getElementById('status');//角色
	var status2 = document.getElementById('status2');//部门
		var regInfo = {
			account: accountBox.value,
			password: passwordBox.value,
		//	userName: userName.value,
			name: name.value,
			enterprise: enterprise.value,
		//	address: address.value,
			status: status.value,
			status2: status2.value,
			
		};
		var passwordConfirm = passwordConfirmBox.value;
		if (passwordConfirm != regInfo.password) {
			layer.msg('密码两次输入不一致!',{icon:1,time:1000});
			return;
		}
		validateInfo(regInfo, function(err) {
			if (err) {
				layer.msg(err,{icon:1,time:1000});
				return;
			}
			
			var index = enterprise.selectedIndex;//企业
			var enterpriseValue =  enterprise.options[index].text
			var enterpriseValue2 =  enterprise.options[index].value
			
			var index2 = status.selectedIndex;//角色
			var statusValue =status.options[index2].text
			var statusValue2 =status.options[index2].value
			
			var index3 = status2.selectedIndex;//部门
			var status2Value =status2.options[index3].text
			var status2Value2 =status2.options[index3].value
			var userinfo = getUserInfo();
			var auditor =userinfo.realname;
			var remarks =auditor+"审核通过"
			var state ="1";
			$.ajax(muser_service+'muser/register',{
		        data:{
					"account": accountBox.value,
					"password": passwordBox.value,
					//"userName": userName.value,
					"name": name.value,
					//"identity": identity.value,
					"enterprise":enterpriseValue,
					//"address": address.value,
					"company":enterpriseValue,//企业
					"profession":statusValue,//角色
					"office":status2Value,//部门
					"companyId":enterpriseValue2,//企业
					"professionId":statusValue2,//角色
					"officeId":status2Value2,//部门
					"auditor":auditor,//审核者
					"remarks":remarks,//备注
					"state":state
				},
		        dataType: 'json',
		        type: 'post',
		        success: function (data) {
		        	
					if(data.msg==0){
						layer.msg('账号已注册!',{icon:1,time:1000});
						return;
					}
			        if(data.msg==1){
			        		var tel = accountBox.value;
							localStorage.setItem("account2",tel)
							layer.msg('注册成功!',{icon:1,time:1000});
							var index = parent.layer.getFrameIndex(window.name);
							parent.$('.btn-refresh').click();
							parent.layer.close(index);
			        }
					var index = parent.layer.getFrameIndex(window.name);
					parent.$('.btn-refresh').click();
					parent.layer.close(index);
		        },
		        error: function(e){
		        	//alert(e);
		        }
		    });
		});
			
	}


//var  urls = 'http://cbms.yintn.com:8092/';
//var  urls ='apis/muser/'



	//企业
function optionStatus(){
	//var urls2 = 'http://cbms.yintn.com:8800/report';
		//$.ajax(muser_service+'muser/selectStatus',{
			$.ajax(report_service+'/getAllCompany',{
				data:{
				},
				dataType: 'json',
				type: 'post',
				//timeout:3000,//超时时间设置为10秒；
				success: function (data) {
					 var Company =  eval('(' + data.list + ')'); //data.list;
					 for(var i = 0; i < Company.length; i ++){
						if(Company[i].companyid!=0000){
							$("#enterprise").append("<option value='"+Company[i].companyid+"' >"+Company[i].companyname+"</option>");
						}
					  }
				},
				error: function(e){
					//alert("错误");
				}
		   });
		   
		   
		   
		   //角色
		   $("#enterprise").change(function(){
			//放开员工编号
		   
			$("#status").empty();
			var enterpriseId = $(this).val();
			//alert(enterpriseId)
				
		   if(enterpriseId!='5'&&enterpriseId!='6'&&enterpriseId!='000'){
			
			document.getElementById("account").placeholder="请输入员工编号"
			//style="display:none"
		   }else{
			document.getElementById("account").placeholder="请输入手机号"
		   }
		   
		   //http://39.100.91.49:8092/muser/selectStatus2?status=1
			var targetUrl =muser_service+'muser/selectStatus2';
			if(enterpriseId == ''){
				//$("#toId").fadeOut("slow");
				return;
			}
			if(enterpriseId=='000'){
				//alert('000')
				//alert("修改")
					var option = '<option value="111" >请选择角色</option>';
					$("#status").append(option); 
					var option2 = '<option value="111" >请选择</option>';
					$("#status2").empty();
					$("#status2").append(option2);	
				return;
			}
		   
			$.ajax({
				type: 'get',
				url: targetUrl,
				data:{
					"status":enterpriseId
				},
				cache:false,    
				dataType:'json',  
				success: function(data){
		   
					$("#status2").empty();
					//var list = data.list;
				 var paProfessions = data.paProfessions;
				 var offices = data.offices;
				 console.log(paProfessions)
				 
				if(paProfessions.length>0){
					 for(var i=0;i<paProfessions.length;i++){
						console.log(JSON.stringify(paProfessions[i]))
						var option = '<option value="'+paProfessions[i].id+'" >'+paProfessions[i].professionName+'</option>';
						$("#status").append(option);
					 }
				 }else{
					var option = '<option value="111" >暂无角色</option>';
					$("#status").append(option); 
				 }
				if(offices.length>0){
					for(var i=0;i<offices.length;i++){
						var option = '<option value="'+offices[i].id+'" >'+offices[i].officename+'</option>';
						$("#status2").append(option);
					}
				}else{
					var option = '<option value="111" >暂无部门</option>';
					$("#status2").append(option);	
				}
					
				},
				error:function(){
					//alert("请求失败");
				}
			});
		   
		   });
		   
		   
		   
		   
		   
		   //职位
			 $("#status").change(function(){
			
			$("#status2").empty();
			$("#enterprise").val();//获取当前选择项的值.
			var companyId=$("#enterprise option:selected");//获取当前选择项.
			companyId = companyId.val();
			var professionId = $(this).val();
			var targetUrl =muser_service+'muser/selectOfficeByCompanyIdAndProfessionId';
			if(professionId == ''){
				//$("#toId").fadeOut("slow");
				return;
			}
				//alert(professionId)
				//alert(companyId)
			$.ajax({
				type: 'get',
				url: targetUrl,
				data:{
					"professionId":professionId,
					"companyId":companyId
				},
				cache:false,    
				dataType:'json',  
				success: function(data){
					//var list = data.list;
					 var offices = data.offices;	
					if(offices.length>0){
						for(var i=0;i<offices.length;i++){
							var option = '<option value="'+offices[i].id+'" >'+offices[i].officename+'</option>';
							$("#status2").append(option);
						}
					}else{
						var option = '<option value="111" >暂无部门</option>';
						$("#status2").append(option);	
					}
					
		   
				},
				error:function(){
					//alert("请求失败");
				}
			});
		   
		   }); 
		   
		   
		   
}

function validateInfo(regInfo, callback) {
				callback = callback || mui.noop;
				regInfo = regInfo || {};
				regInfo.account = regInfo.account || '';//账号
				regInfo.password = regInfo.password || '';//密码
				//regInfo.userName = regInfo.userName || '';//员工编号
				regInfo.name = regInfo.name || '';//姓名
				regInfo.enterprise = regInfo.enterprise || '';//所属企业
				//regInfo.address = regInfo.address || '';//所在地址
				regInfo.status = regInfo.status || '';//角色
				regInfo.status2 = regInfo.status2 || '';//角色
				console.log("======"+regInfo.enterprise)
				
				if (regInfo.account.length < 1) {
					return callback('账号不能为空');
				}
				if(regInfo.account.length < 8||regInfo.account.length>11){
			        return  callback('账号不符合条件'); 
			    }

				if (regInfo.name.length < 1) {
					return callback('请输入姓名');
				}
				if (regInfo.enterprise==000) {
					return callback('选择所属企业');
				}
				if (regInfo.status.length==000) {
					return callback('请选择所属角色');
				}
				if (regInfo.status2.length==000) {
					return callback('请选择所属部门');
				}
			/* 	if (regInfo.address.length < 1) {
					return callback('请输入所在地址');
				} */
				if (regInfo.password.length < 1) {
					return callback('密码不能为空');
				}
				/*if (regInfo.userName.length < 1) {
					return callback('请输入员工编号');
				}*/


				return callback();
			}





</script> 
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>